<?php

namespace App\Admin\Controllers;

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;

class LoginController extends Controller
{
    public function index()
    {
        return view('admin.login.index');
    }

    public function login()
    {
        //验证
        $this->validate(request(), [
            'name' => 'required',
            'password' => 'required'
        ]);

        //逻辑
        $user = request(['name', 'password']);

        if(\Auth::guard('admin')->attempt($user)) {
            return redirect('/admin/home');
        }
        //渲染
        return \Redirect::back()->withErrors("用户名或密码错误");
    }

    public function logout()
    {
        \Auth::guard("admin")->logout();
        return redirect('/admin/login');
    }
}
